package com.sxr.spring;
import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

@Configuration
public class TomcatConfig {
    @Value("${custom.tomcat.relaxed-path-chars:}")
    private String relaxedPathChars;
    @Value("${custom.tomcat.relaxed-query-chars:}")
    private String relaxedQueryChars;

    @Bean
    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
        return factory -> factory.addConnectorCustomizers((Connector connector) -> {
            if(!"".equals(relaxedPathChars)) connector.setProperty("relaxedPathChars", relaxedPathChars);
            if(!"".equals(relaxedQueryChars)) connector.setProperty("relaxedQueryChars", relaxedQueryChars);
        });
    }
}
